import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import i18n, { getLocale } from '@/locales'
import store from '@/store'
import { LocalStorage } from '@/api/LocalStorage';

export interface IAppState {
  language: string
}

@Module({ dynamic: true, store, name: 'app' })
class App extends VuexModule implements IAppState {
  public language = getLocale();


  @Mutation
  private SET_LANGUAGE(language: string) {
    i18n.locale = language;
    LocalStorage.setLanguage(this.language);
  }

  @Action
  public SetLanguage(language: string) {
    this.SET_LANGUAGE(language)
  }
}

export const AppStore = getModule(App)
